#! /bin/sh
# Author: Daniel Wasilew <daniel.wasilew@codeminer.org>
#

NAME=parts-server
DAEMON_DESTINATION=/usr/bin/$NAME
INIT_SCRIPT_DESTINATION=/etc/init.d/$NAME
MEDIA_HOME=/media/data
USER=parts

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi


if [ ! -d "$MEDIA_HOME" ]; then
   echo "This script expects "$MEDIA_HOME" to exist" 1>&2
   exit 1
fi

if [
echo "Create default folder structure"

mkdir $MEDIA_HOME/bin

mkdir "$MEDIA_HOME/artworks"
mkdir "$MEDIA_HOME/configuration"
mkdir "$MEDIA_HOME/tmp"
mkdir "$MEDIA_HOME/help"
mkdir "$MEDIA_HOME/logs"

echo "Adjust wrights"
chown -R $USER:root "$MEDIA_HOME"

echo "Copy scripts to teh desired locations"
cp "$MEDIA_HOME/bin/srcipts/parts-init "$INIT_SCRIPT_DESTINATION"
cp "$MEDIA_HOME/bin/srcipts/parts-server "$DAEMON_DESTINATION"

echo "Adjust wrights"
chmod ugo+x "$INIT_SCRIPT_DESTINATION"
chmod ugo+x "$DAEMON_DESTINATION"

udpate-rc.d "$INIT_SCRIPT_DESTINATION" defaults

echo "finished - now start with service parts-server start"
